package com.example.hystrixDemo.rxjava;/**
 * @Deacription TODO
 * @Author baohuajie
 * @Date 2020/12/15 11:51
 * @Version 1.0
 **/


import rx.Observable;
import rx.Observer;
import rx.Subscriber;
import rx.functions.Action1;
import rx.functions.Func1;

/**
 *@Deacription TODO
 *@Author baohuajie
 *@Date 2020/12/15 11:51
 *@Version 1.0
 **/
public class Main2 {

    public static void main(String[] args) {
        Observable<String> observable = Observable.create(new Observable.OnSubscribe<String>() {

            @Override
            public void call(Subscriber<? super String> subscriber) {
                for (int i = 0; i < 10; i++) {
                    subscriber.onNext(String.valueOf(i));
                }
                subscriber.onCompleted();
            }
        });

        Observer<String> observer = new Observer<String>(){

            @Override
            public void onCompleted() {
                System.out.println("消息接收完毕");
            }

            @Override
            public void onError(Throwable e) {

            }

            @Override
            public void onNext(String s) {
                System.out.println("观察者收到消息:" + s);
            }
        };

        observable.map(new Func1<String, Object>() {

            @Override
            public Object call(String s) {
                return null;
            }
        }).subscribe((Action1<? super Object>) observer);
        
    }
}
